using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Web;
public class FollowsendUtil
{
	public static float float_0 = 0.8f;
	public static int int_0 = 60000;
	public static int int_1 = 60000;
	public static string string_0 = "";
	public static bool smethod_0(string user_name, string content, out string out_log)
	{
		string text = Directory.GetCurrentDirectory() + "\\config\\临时文件夹\\followsend";
		if (!Directory.Exists(text))
		{
			Directory.CreateDirectory(text);
		}
		string text2 = DateTime.Now.ToString("yyyyMMddHHmmss");
		string text3 = text + "\\" + text2;
		if (Directory.Exists(text3))
		{
			out_log = "";
			return true;
		}
		Directory.CreateDirectory(text3);
		bool result;
		try
		{
			content = content.Replace("<img", "<IMG");
			int num = 0;
			while (true)
			{
				num = content.IndexOf("<IMG", num);
				if (num == -1)
				{
					break;
				}
				int num2 = content.IndexOf("src", num);
				int num3 = content.IndexOf("SRC", num);
				int num4 = num2;
				if (num4 == -1 || (num4 > num3 && num3 != -1))
				{
					num4 = num3;
				}
				int num5 = content.IndexOf("\"", num4) + 1;
				string text4 = content.Substring(num5, content.IndexOf("\"", num5) - num5);
				if (text4.StartsWith("file:///"))
				{
					string text5 = HttpUtility.UrlDecode(text4.Replace("file:///", "").Replace("/", "\\")).Replace("%20", " ");
					string text6 = text3 + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + text5.Substring(text5.LastIndexOf("."));
					bool flag = File.Exists(text6);
					while (flag)
					{
						text6 = string.Concat(new object[]
						{
							text3,
							"\\",
							DateTime.Now.ToString("yyyyMMddHHmmss"),
							int.Parse(DateTime.Now.ToString("fff")) + 1,
							text5.Substring(text5.LastIndexOf("."))
						});
						flag = File.Exists(text6);
					}
					try
					{
						File.Copy(text5, text6);
						"file:///" + text6.Replace(" ", "%20").Replace("{", "%7B").Replace("}", "%7D").Replace("%", "%25").Replace("\\", "/");
						content = content.Replace(text4, "{LCL_DIR}" + text6.Substring(text6.LastIndexOf("\\") + 1));
					}
					catch (Exception)
					{
					}
				}
				num++;
			}
			string path = text3 + "\\content.html";
			if (File.Exists(path))
			{
				File.Delete(path);
			}
			FileStream fileStream = new FileStream(path, FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.GetEncoding("GB2312"));
			streamWriter.Write(content);
			streamWriter.Flush();
			streamWriter.Close();
			streamWriter.Dispose();
			fileStream.Close();
			fileStream.Dispose();
			string value = "";
			string[] files = Directory.GetFiles(text3);
			for (int i = 0; i < files.Length; i++)
			{
				string file_name = files[i];
				while (true)
				{
					UploadUtil uploadUtil = new UploadUtil();
					uploadUtil.add_field("data", "type=uploadfile&username=" + user_name + "&fid=" + text2);
					uploadUtil.add_file("upfile", file_name, "application/octet-stream");
					uploadUtil.upload("http://" + Config.user_url + "/followsend.php", ref value);
					if ("ok".Equals(value))
					{
						break;
					}
					Thread.Sleep(1500);
				}
			}
			while (true)
			{
				UploadUtil uploadUtil = new UploadUtil();
				uploadUtil.add_field("data", "type=completeupload&datatype=followsend&username=" + user_name + "&fid=" + text2);
				uploadUtil.upload("http://" + Config.user_url + "/followsend.php", ref value);
				if ("ok".Equals(value))
				{
					break;
				}
				Thread.Sleep(1500);
			}
			out_log = "";
			result = true;
		}
		catch (Exception ex)
		{
			out_log = ex.ToString();
			result = false;
		}
		return result;
	}
	public static bool smethod_1(string string_1, GClass12 gclass12_0, string string_2, out string string_3)
	{
		string text = Directory.GetCurrentDirectory() + "\\config\\临时文件夹\\addHotShare";
		if (!Directory.Exists(text))
		{
			Directory.CreateDirectory(text);
		}
		string text2 = DateTime.Now.ToString("yyyyMMddHHmmss");
		string text3 = text + "\\" + text2;
		if (Directory.Exists(text3))
		{
			string_3 = "";
			return true;
		}
		Directory.CreateDirectory(text3);
		bool result;
		try
		{
			string_2 = string_2.Replace("<img", "<IMG");
			int num = 0;
			while (true)
			{
				num = string_2.IndexOf("<IMG", num);
				if (num == -1)
				{
					break;
				}
				int num2 = string_2.IndexOf("src", num);
				int num3 = string_2.IndexOf("SRC", num);
				int num4 = num2;
				if (num4 == -1 || (num4 > num3 && num3 != -1))
				{
					num4 = num3;
				}
				int num5 = string_2.IndexOf("\"", num4) + 1;
				string text4 = string_2.Substring(num5, string_2.IndexOf("\"", num5) - num5);
				if (text4.StartsWith("file:///"))
				{
					string text5 = HttpUtility.UrlDecode(text4.Replace("file:///", "").Replace("/", "\\")).Replace("%20", " ");
					string text6 = text3 + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + text5.Substring(text5.LastIndexOf("."));
					bool flag = File.Exists(text6);
					while (flag)
					{
						text6 = string.Concat(new object[]
						{
							text3,
							"\\",
							DateTime.Now.ToString("yyyyMMddHHmmss"),
							int.Parse(DateTime.Now.ToString("fff")) + 1,
							text5.Substring(text5.LastIndexOf("."))
						});
						flag = File.Exists(text6);
					}
					try
					{
						File.Copy(text5, text6);
						"file:///" + text6.Replace(" ", "%20").Replace("{", "%7B").Replace("}", "%7D").Replace("%", "%25").Replace("\\", "/");
						string_2 = string_2.Replace(text4, "{LCL_DIR}" + text6.Substring(text6.LastIndexOf("\\") + 1));
					}
					catch (Exception)
					{
					}
				}
				num++;
			}
			string path = text3 + "\\hot.html";
			if (File.Exists(path))
			{
				File.Delete(path);
			}
			FileStream fileStream = new FileStream(path, FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.GetEncoding("GB2312"));
			streamWriter.Write(string_2);
			streamWriter.Flush();
			streamWriter.Close();
			streamWriter.Dispose();
			fileStream.Close();
			fileStream.Dispose();
			string value = "";
			string[] files = Directory.GetFiles(text3);
			for (int i = 0; i < files.Length; i++)
			{
				string file_name = files[i];
				while (true)
				{
					UploadUtil uploadUtil = new UploadUtil();
					uploadUtil.add_field("data", "type=uploadfile&destfolder=" + FollowsendUtil.smethod_2(gclass12_0.int_0) + "/" + text2);
					uploadUtil.add_file("upfile", file_name, "application/octet-stream");
					uploadUtil.upload("http://" + Config.user_url + "/uploadfile.php", ref value);
					if ("ok".Equals(value))
					{
						break;
					}
					Thread.Sleep(1500);
				}
			}
			while (true)
			{
				string url = "http://" + Config.user_url + ":80/hotshare.php";
				value = new HttpService().post(url, string.Concat(new object[]
				{
					"softwarename=alibridge&type=addhotshare&hottype=",
					gclass12_0.int_0,
					"&username=",
					string_1,
					"&hid=",
					text2,
					"&itemid=",
					gclass12_0.string_1,
					"&title=",
					gclass12_0.string_2,
					"&price=",
					gclass12_0.string_3,
					"&cmsRate=",
					gclass12_0.string_4
				}));
				if ("ok".Equals(value))
				{
					break;
				}
				Thread.Sleep(1500);
			}
			string_3 = "";
			result = true;
		}
		catch (Exception ex)
		{
			string_3 = ex.ToString();
			result = false;
		}
		return result;
	}
	public static string smethod_2(int int_2)
	{
		if (int_2 != 1)
		{
			if (int_2 == 2)
			{
				return "selhotshare";
			}
			if (int_2 == 3)
			{
				return "sharehotshare";
			}
			if (int_2 == 4)
			{
				return "mutualhotshare";
			}
		}
		return "hotshare";
	}
	public static void smethod_3(object object_0)
	{
		string text = (string)object_0;
		string text2 = Directory.GetCurrentDirectory() + "\\config\\临时文件夹\\follow";
		try
		{
			if (!Directory.Exists(text2))
			{
				Directory.CreateDirectory(text2);
				goto IL_26;
			}
			goto IL_26;
			IL_26:
			goto IL_2B;
		}
		catch
		{
			goto IL_2B;
		}
		while (true)
		{
			try
			{
				UploadUtil uploadUtil;
				string text3;
				while (true)
				{
					IL_2B:
					if (File.Exists(Directory.GetCurrentDirectory() + "\\admin.txt"))
					{
						FollowsendUtil.int_0 = FollowsendUtil.int_1;
					}
					uploadUtil = new UploadUtil();
					text3 = "";
					uploadUtil.add_field("data", "type=getlastfollowsndid&username=" + text);
					uploadUtil.upload("http://" + Config.user_url + "/followsend.php", ref text3);
					if (text3 != null && text3.Length > 14)
					{
						uploadUtil = new UploadUtil();
						uploadUtil.add_field("data", "type=getlastfollowsndid&username=" + text);
						uploadUtil.upload("http://" + Config.user_url + "/followsend.php", ref text3);
					}
					if (text3 == null || text3.Equals(""))
					{
						Thread.Sleep(FollowsendUtil.int_0);
					}
					else
					{
						if (!text3.Equals(FollowsendUtil.string_0))
						{
							break;
						}
						Thread.Sleep(FollowsendUtil.int_0);
					}
				}
				FollowsendUtil.string_0 = text3;
				uploadUtil.add_field("data", "type=getlist&username=" + text);
				if (!uploadUtil.upload("http://" + Config.user_url + "/followsend.php", ref text3))
				{
					uploadUtil.upload("http://" + Config.user_url + "/followsend.php", ref text3);
				}
				if (!text3.Equals(""))
				{
					bool flag = false;
					string[] array = text3.Split(new char[]
					{
						'\t'
					});
					int i = 0;
					while (i < array.Length)
					{
						string text4 = array[i];
						if (text4.Length != 14)
						{
							flag = true;
							IL_1C2:
							if (flag)
							{
								uploadUtil = new UploadUtil();
								uploadUtil.add_field("data", "type=getlist&username=" + text);
								uploadUtil.upload("http://" + Config.user_url + "/followsend.php", ref text3);
								goto IL_1FF;
							}
							goto IL_1FF;
						}
						else
						{
							i++;
						}
					}
					goto IL_1C2;
				}
				IL_1FF:
				if (!text3.Equals(""))
				{
					string[] array2 = text3.Split(new char[]
					{
						'\t'
					});
					for (int j = 0; j < array2.Length; j++)
					{
						string text5 = array2[j];
						string text6 = text2 + "\\" + text5;
						if (!Directory.Exists(text6))
						{
							Directory.CreateDirectory(text6);
							WebClient webClient = new WebClient();
							if (File.Exists(text6 + "\\content.html"))
							{
								File.Delete(text6 + "\\content.html");
							}
							try
							{
								webClient.DownloadFile(string.Concat(new string[]
								{
									"http://",
									Config.user_url,
									"/sendtask/",
									text,
									"/",
									text5,
									"/content.html"
								}), text6 + "\\content.html");
								goto IL_495;
							}
							catch
							{
								webClient.DownloadFile(string.Concat(new string[]
								{
									"http://",
									Config.user_url,
									"/sendtask/",
									text,
									"/",
									text5,
									"/content.html"
								}), text6 + "\\content.html");
								goto IL_495;
							}
							IEnumerator enumerator;
							try
							{
								IL_34F:
								while (enumerator.MoveNext())
								{
									string text7 = (string)enumerator.Current;
									if (File.Exists(text6 + "\\" + text7))
									{
										File.Delete(text6 + "\\" + text7);
									}
									try
									{
										webClient.DownloadFile(string.Concat(new string[]
										{
											"http://",
											Config.user_url,
											"/sendtask/",
											text,
											"/",
											text5,
											"/",
											text7
										}), text6 + "\\" + text7);
									}
									catch
									{
										webClient.DownloadFile(string.Concat(new string[]
										{
											"http://",
											Config.user_url,
											"/sendtask/",
											text,
											"/",
											text5,
											"/",
											text7
										}), text6 + "\\" + text7);
									}
								}
							}
							finally
							{
								IDisposable disposable = enumerator as IDisposable;
								if (disposable != null)
								{
									disposable.Dispose();
								}
							}
							UtilFile.write(text6 + "\\0.txt", "");
							goto IL_48A;
							IL_495:
							enumerator = FollowsendUtil.smethod_4(text6 + "\\content.html", text5).GetEnumerator();
							goto IL_34F;
						}
						IL_48A:;
					}
				}
			}
			catch
			{
			}
			Thread.Sleep(FollowsendUtil.int_0);
			goto IL_2B;
		}
	}
	public static ArrayList smethod_4(string string_1, string string_2)
	{
		ArrayList arrayList = new ArrayList();
		StreamReader streamReader = new StreamReader(string_1, Encoding.GetEncoding("GB2312"));
		string text = streamReader.ReadToEnd();
		streamReader.Close();
		streamReader.Dispose();
		int num = 0;
		while ((num = text.IndexOf("{LCL_DIR}", num)) != -1)
		{
			int length = text.IndexOf("\"", num) - num - 9;
			string value = text.Substring(num + 9, length);
			arrayList.Add(value);
			num++;
		}
		text = text.Replace("{LCL_DIR}", "file:///" + (Directory.GetCurrentDirectory() + "\\config\\临时文件夹\\follow\\" + string_2).Replace("\\", "/").Replace(" ", "%20") + "/");
		File.Delete(string_1);
		FileStream fileStream = new FileStream(string_1, FileMode.Create);
		StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.GetEncoding("GB2312"));
		streamWriter.Write(text);
		streamWriter.Flush();
		streamWriter.Close();
		streamWriter.Dispose();
		fileStream.Close();
		fileStream.Dispose();
		return arrayList;
	}
}
